<!--
* description: 交付地管理---关联订单
* author:xlc
* createdDate: 2020-12-14
-->
<template>
  <div class="app-container app-container-table">
    <el-dialog
      v-dialogDrag
      style="margin:15px"
      :visible="popupsVisible"
      :title="titleName"
      center
      width="60%"
      :append-to-body="true"
      :close-on-click-modal="false"
      @close="closeEdit"
    >
      <dialogHeader slot="title" :title="titleName" :style-type="$store.state.app.dialogType" />
      <div>
        <!-- 表单组件 -->
        <one-table-template
          ref="multipleTable"
          :dynamic-buttons="tableButtons"
          :dynamic-components="tableComponents"
          :dynamic-api-config="apiConfig"
          :dynamic-table-cols="tableCols"
          :dynamic-form-fields="formField"
          :dynamic-is-show-select="false"
          :dynamic-is-show-more-btn="true"
          :dynamic-table-defult-height="300"
          :callback-obj="callbackObj"
        />
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import { orgApis } from '@/api/vesalesapi.js'
import OneTableTemplate from '@/components/templates/oneTable'
import dialogHeader from '@/components/dialogHeader'
import Vue from 'vue'
export default {
  components: {
    OneTableTemplate,
    dialogHeader
  },
  mixins: [oneTableWithViewTemplateMixins],
  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, 'supplierMessage-edit'], () => {
      next()
    })
  },
  props: {
    popupsVisible: {
      type: Boolean,
      default: false
    },
    dataForForm: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path
    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])
    return {
      titleName: '关联订单选择',
      selectdata: {
        type: Object,
        default: () => {}
      },
      // 网格查询API配置对象
      apiConfig: orgApis.deliveryPlaceChangeOrderQuery,
      // 动态组件-按钮
      tableButtons: [
        // {
        //   compKey: 'btnKey1',
        //   type: 'primary',
        //   size: 'small',
        //   clickEvent: () => this.confirm(),
        //   text: '确认',
        //   name: 'confirm', // 按钮图标样式
        //   position: 'left',
        //   fuzzySearch: true
        // },
        // {
        //   compKey: 'btnKey4',
        //   type: '',
        //   size: 'small',
        //   clickEvent: () => this.closeEdit(),
        //   text: '取消',
        //   name: 'cancel',
        //   position: 'left'
        // },
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'),
          name: 'search', // 按钮图标样式
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey4',
          type: '',
          size: 'small',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          name: 'reset',
          position: 'right' // 重置
        }
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            // 显示组件
            {
              compKey: 'compKey1',
              labelName: 'DMS订单号：',
              codeField: 'saleOrderCode',
              isMul: false,
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: 'VIN码：',
              codeField: 'vin',
              isMul: false,
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '销售计划号：',
              codeField: 'salePlanCode',
              isMul: false,
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey4',
              labelName: '客户姓名：',
              codeField: 'custName',
              isMul: false,
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey5',
              labelName: '客户电话：',
              codeField: 'custTel',
              isMul: false,
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false
            },
            // {
            //   compKey: 'compKey6',
            //   labelName: '交付城市：',
            //   codeField: 'cityId',
            //   filterable: true,
            //   oFields: 'cityId,cityName',
            //   customObj: { api: orgApis.listDeliverCity, selectType: '1' },
            //   component: () => import('@/components/org/commonSelect'),
            //   isMust: false,
            //   span: 6
            // },
            // {
            //   compKey: 'compKey7',
            //   labelName: '交付门店：',
            //   codeField: 'deliveryDlrCode',
            //   filterable: true,
            //   component: () => import('@/components/org/commonSelect'),
            //   oFields: 'deliveryDlrCode,deliveryDlrShortName',
            //   parentFileds: 'value:cityId',
            //   customObj: {
            //     listQuery: { cityId: '' },
            //     api: orgApis.ListOfDeliveryStore, selectType: '1'
            //   },
            //   isMust: false,
            //   span: 6
            // },
            {
              compKey: 'compKey8',
              labelName: '交付专员：',
              codeField: 'empId',
              textField: 'codeName',
              filterable: true,
              component: () => import('@/components/org/commonSelect'),
              parentFileds: 'value:deliveryDlrCode|cityId',
              oFields: 'empId,codeName',
              customObj: {
                listQuery: {
                  deliveryDlrCode: '',
                  cityId: ''
                },
                api: orgApis.ListOfdeliveryPersonnel, selectType: '1'
              },
              isMust: false,
              span: 6
            },
            {
              compKey: 'compKey9',
              labelName: '基础车型名称：',
              codeField: 'carConfigId',
              textField: 'carConfigCn',
              component: () => import('@/components/org/commonSelect'),
              oFields: 'carConfigId,carConfigCn',
              customObj: {
                api: orgApis.listOfCarModel, selectType: '1'
              },
              isMust: false
            }
          ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'saleOrderCode',
              label: 'DMS订单编号'
            },
            {
              prop: 'orderStauts',
              label: '订单状态'
            },
            {
              prop: 'salePlanCode',
              label: '销售计划号'
            },
            {
              prop: 'vin',
              label: 'VIN码'
            },
            {
              prop: 'custName',
              label: '客户姓名'
            },
            {
              prop: 'custTel',
              label: '客户电话'
            },
            {
              prop: 'cityName',
              label: '交付城市'
            },
            {
              prop: 'dlrShortName',
              label: '交付门店'
            },
            {
              prop: 'empName',
              label: '交付专员'
            },
            {
              prop: 'carconfigCN',
              label: '基础车型名称'
            },
            {
              prop: 'dlrId',
              label: '交付门店ID',
              hidden: true
            },
            {
              prop: 'carStockHouseId',
              label: '仓库ID',
              hidden: true
            }
          ],
      formField: {
        saleOrderCode: '',
        orderStatus: '',
        salePlanCode: '',
        vin: '',
        custName: '',
        custTel: '',
        cityId: '',
        deliveryDlrCode: '',
        empId: '',
        carConfigId: ''
      },
      // 是否使用刷新Key的方式刷新弹窗
      resetDialogKey: false,
      // 单表格模版页面组件回调事件
      callbackObj: {
        onRowDbClick: (row) => {
          this.selectdata = row
          this.confirm()
        },
        // 手动勾选时
        // onCheckSelect: (selection, row) => {
        //   // 清除所有选中
        //   this.$refs.multipleTable.$refs.multipleTable.clearSelection()
        //   if (selection.length === 0) return
        //   // 将当前点击项选中
        //   this.selectdata = row
        //   this.$refs.multipleTable.$refs.multipleTable.toggleRowSelection(row, true)
        // },
        onCheckSelectChange: (selection) => {
          this.onCheckSelectChange1(selection)
        }
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.queryTable(1)
    })
  },
  methods: {
    onCheckSelectChange1(selection) {
      var btns = this.tableButtons[2]
      const isCheck = selection && selection.length > 0
      btns.disabled = !isCheck
    },
    // 确认
    confirm() {
      this.$emit('save', this.selectdata)
      this.closeEdit()
    },
    // 关闭弹窗
    closeEdit(type) {
      this.$emit('close', type)
    },
    // 保存
    save(res) {
    }
  }
}
</script>
<style lang="scss" scoped>
/deep/ .el-table__header .el-checkbox{
    display:none
  }
</style>
